#pragma once
#include<iostream>
#include"Socket.hpp"
#include<functional>

using callback_t = std::function<std::string(std::string&)>;

class Reactor;

class Connection
{
public:
    Connection():_sockfd(-1),_own(nullptr)
    {}
    virtual ~Connection(){}

    //读、写、异常
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;

    //sockfd Get函数
    int Sockfd()
    {
        return _sockfd;
    }
    void SetSockfd(int sockfd){ _sockfd = sockfd;}
    void SetEvents(uint32_t events) {_events = events;}
    uint32_t Events(){return _events;}
    Reactor* Owner(){return _own;}
    void SetOwner(Reactor* own){_own = own;}
    void SetClientAddr(InetAddr& clientaddr) {_peer = clientaddr;}
    void SetCB(callback_t cb){_cb = cb;}

    //连接
protected:
    int _sockfd;
    InetAddr _peer;//用户信息
    uint32_t _events;//关心的事件

    //输入输出缓冲区
    std::string _inbuffer;
    std::string _outbuffer;

    //回指向Reactor 的指针
    Reactor * _own;

    //上层处理数据的函数
    callback_t _cb;
};